function updatePrice() {

    let cart_item = document.querySelectorAll('.cart_item');
    let totalPrice = 0;
    cart_item.forEach(function(cart_item) {

        if (cart_item.querySelector('.cart_inp').checked) {

            let count = cart_item.querySelector('.count').value;
            let price = cart_item.querySelector('.cprice').getAttribute('data-price');
            totalPrice = totalPrice + parseFloat(price) * count;
            console.log(totalPrice);
        }
    });
    document.querySelector('.total_price').innerText = totalPrice;
}

window.onload = function () {
    let cartinps = document.querySelectorAll('.cart_inp');
    cartinps.forEach(function (cart_inp) {
        cart_inp.onchange = function () {
            updatePrice();
        }
    });

    let sub = document.querySelectorAll('.sub');
    sub.forEach(function(su) {
        su.onclick = function (event) {
            let count = su.parentElement.querySelector('.count').value;
            if (parseInt(count) > 1) {
                su.parentElement.querySelector('.count').value = parseInt(count) - 1;
                console.log(su.parentElement.querySelector('.count').value);
                updatePrice();
            }
        }
    });

    let add = document.querySelectorAll('.add');
    add.forEach(function (ad) {
        ad.onclick = function (event) {
            let count = ad.parentElement.querySelector('.count').value;
            ad.parentElement.querySelector('.count').value = parseInt(count) + 1;
            console.log(ad.parentElement.querySelector('.count').value);
            updatePrice();
        }
    });
}